﻿using System;
using IM.Interfaces;
using IM.DataTypes;
using Common.Interfaces;

namespace IM.GUI.Widgets.ExtensionCommands
{
	class ChatMessageCommand : IUpdateCommand<ChatMessage>
    {
		public void Update(ChatMessage updatePar)
        {
			if (updatePar != null)
			{
				var control = IM.GUI.Widgets.WidgetsProvider.Activate().Conversation;

				if (control is IM.GUI.Conversation.ConversationWindow)
				{
					var conversation = control as IM.GUI.Conversation.ConversationWindow;
					ChatMessage message = updatePar;

					conversation.AddIncomingMessage(message.Sender, message.Message);
				}
				else
				{
					Logging.Logger.AddWarning("No appropriate conversation window found");
				}
			}
			else
				Logging.Logger.AddWarning("ChatMessageCommand: Incoming updatePar is null, ChatMessage expected.");
        }
	}
}
